package com.xiangyu.demo.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * java类简单作用描述
 *
 * @ProjectName: springboot-demo
 * @Package: com.xiangyu.demo.filter
 * @Description: java类作用描述
 * @Author: 向羽
 * @CreateDate: 2018/1/19 10:54
 * @UpdateUser: 向羽
 * @UpdateDate: 2018/1/19 10:54
 * @UpdateRemark: The modified content
 * @Version: 2.0
 */

public class CustomFilter implements Filter {
    private Logger logger = LoggerFactory.getLogger(CustomFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.debug("CustomFilter 过滤器初始化！");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        /*String devType = request.getHeader("Dev");
        if (devType==null){
            response.sendError(HttpStatus.UNAUTHORIZED.value(),"用户登入失效！");
            return;
        }
        logger.debug("devType=====>:"+devType);
        if (!devType.equalsIgnoreCase("PC")){
            response.sendError(HttpStatus.UNAUTHORIZED.value(),"用户登入失效！");
        }*/
        filterChain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
